<p><?= $this->Html->link("&laquo; Nazad na listu", "/prevoznici", array('escape'=>false)) ?></p>
<?= $this->Form->create("Carrier", array(
	'url'   => '/prevoznici/sacuvaj', 
	'class' => 'entity-form'
)); ?>

	<?= $this->Form->hidden("id", array("value" => @$carrier['Carrier']['id'])) ?>
	
	<?= $this->Form->label("name", "Naziv:") ?>
	<?= $this->Form->text("name", array("value" => @$carrier['Carrier']['name'])) ?>
	<span class="error-message-conatiner"><?= $this->Form->error("name", null, array('style'=>'width:150px')) ?></span>
	
	<hr>
	<?= $this->Form->label("vozila", "Vozila:") ?>
	<div class="left multi-inputs" id="vehicles">
		<? 
			$vehicles = @$carrier['Vehicle'];
			if(empty($vehicles)) {
				$vehicles = array(array(
					"id"     => 0,
					"model"  => '',
					"plates" => ''
				));
			}
		?>
		<? foreach($vehicles as $k=>$vehicle): ?>
		<div class="item">
			<?= $this->Form->hidden("Vehicle.{$k}.id", array('value' => $vehicle['id'])) ?>
			<?= $this->Form->text("Vehicle.{$k}.plates", array('value' => $vehicle['plates'], 'placeholder' => 'Reg.Broj', 'class'=>'xmedium')) ?>
			<?= $this->Form->text("Vehicle.{$k}.model", array('value' => $vehicle['model'], 'placeholder' => 'Model')) ?>
		</div>
		<? endforeach; ?>
	</div>
	
	<hr>
	<?= $this->Form->label("vozaci", "Vozači:") ?>
	<div class="left multi-inputs" id="drivers">
		<? 
			$drivers = @$carrier['Driver'];
			if(empty($drivers)) {
				$drivers = array(array(
					"id"     => 0,
					"name"  => '',
					"id_number" => ''
				));
			}
		?>
		<? foreach($drivers as $k=>$driver): ?>
		<div class="item">
			<?= $this->Form->hidden("Driver.{$k}.id", array('value' => $driver['id'])) ?>
			<?= $this->Form->text("Driver.{$k}.name", array('value' => $driver['name'], 'placeholder' => 'Ime')) ?>
			<?= $this->Form->text("Driver.{$k}.id_number", array('value' => $driver['id_number'], 'placeholder' => 'Br.L.K.', 'class' => 'xmedium')) ?>
		</div>
		<? endforeach; ?>
	</div>
	
	<?= $this->Form->submit("Sačuvaj", array('div'=>false)) ?>
<?= $this->Form->end() ?>

<script type="text/javascript">
function vehicles_onAdd(item) {
	item.find("input[type=hidden],input[type=text]").val('');
}
function drivers_onAdd(item) {
	item.find("input[type=hidden],input[type=text]").val('');
}
</script>
